home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-05 | 1.1 KB | 42 lines | [MATF/MATL] |
- function Clist = crvfit(x,y,ct)
- % Clist = crvfit(x,y,ct)
- % Construct the least squares curve fit.
- % x is an 1xn abscissa vector, input.
- % y is an 1xn ordinate vector, input.
- % ct is the curve type, input.
- % Clist is the coefficient list, output.
- if length(ct)==0, ct=2; end
- L = 0;
- if ct==10,
- clc;
- disp(' Y = '),disp(y),...
- disp(' y(x) = L/(1 + C exp(Ax))'),...
- disp(' lim y(x) = L'),...
- disp(' x-->oo'),...
- L = input('Enter the constant L = ');
- end
- if length(L)==0, L=0; end
- if L <= max(y),
- L=max(y)+0.01*abs(max(y));
- end
- if ct==1, X=x.^(-1); Y=y; end
- if ct==2, X=x.*y; Y=y; end
- if ct==3, X=x; Y=y.^(-1); end
- if ct==4, X=x.^(-1); Y=y.^(-1); end
- if ct==5, X=log(x); Y=y; end
- if ct==6, X=x; Y=log(y); end
- if ct==7, X=log(x); Y=log(y); end
- if ct==8, X=x; Y=sqrt(y).^(-1); end
- if ct==9, X=x; Y=log(y./x); end
- if ct==10,X=x; Y=log(L.*y.^(-1)-1); end
- AB = polyfit(X,Y,1);
- A = AB(1);
- B = AB(2);
- C = 0; D = 0;
- if ct==2, C=-1/A; D=-B/A; end
- if ct==6, C=exp(B); end
- if ct==7, C=exp(B); end
- if ct==9, C=exp(B); D=-A; end
- if ct==10,C=exp(B); end
- Clist = [A B C D L];
-